<template>
  <div>
    <control :config="config" />
    <div class="layout-header">

      <el-button
        type="primary"
        icon="el-icon-plus"
        style="margin-left:0px"
        @click="changeEdit(0)"
      >添加</el-button>

      <el-button type="success" icon="el-icon-check" @click="submitStyle()">保存</el-button>
    </div>
    <!-- 活动区图片叠放样式 -->
    <div style="margin-top:20px;">样式选择</div>
    <div class="activity-style">
      <ul>
        <li v-for="(item,index) in style_options" :key="index" :class="is_style_ac == index ? 'style-ac '+item.className :item.className" @click="chooseStyle(index)">
          <img :src="item.url" alt="">
        </li>
      </ul>

    </div>
    <div class="layout-content">
      <el-table
        :data="tableData"
        stripe

        highlight-current-row
        style="width: 100%;margin-top:50px"
      >
        <el-table-column align="center" prop="title" label="活动昵称" width="100" />
        <el-table-column align="center" prop="thumb" label="封面" width="100">
          <template slot-scope="scope">
            <img :src="scope.row.thumb" width="50%">
          </template>
        </el-table-column>
        <el-table-column align="center" prop="banner" label="轮播" width="100">
          <template slot-scope="scope">
            <img :src="scope.row.banner" width="50%">
          </template>
        </el-table-column>
        <el-table-column align="center" prop="type" label="活动类型" width="80">
          <template slot-scope="scope">
            <el-tag
              :type="scope.row.type%2 == 0 ? 'primary' : 'success'"
              disable-transitions
            >{{ type_arr[scope.row.type]}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="status" label="是否启用" width="80">
          <template slot-scope="scope">
            <el-button
              :type="scope.row.status === 1 ? 'primary' : 'success'"
              size="mini"
              @click="change_status(scope.row.id,'status' ,scope.row.status)"
            >{{ scope.row.status === 1 ? "是" : "否" }}</el-button>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="sort" label="排序" width="80" />
        <el-table-column
          align="center"
          prop="telephone"
          fixed="right"
          width="120"
          label="操作"
        >
          <template slot-scope="scope">
            <el-button type="primary" size="mini" icon="el-icon-edit" @click="changeEdit(scope.row.id)" />
            <el-button
              style="margin-left:0px"
              type="danger"
              size="small"
              icon="el-icon-delete"
              @click="onDel(scope.row.id)"
            />
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-pagination
      :current-page="current_page"
      :page-size="per_page"
     layout="total, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
import control from '../../../components/control/control'
export default {
  name: 'ActivityEdit',
  components: { control },
  data() {
    return {
      config: [
        { type: 'text', placeholder: '请输入活动昵称', field: 'title', val: '' }
      ],
      value: '',
      is_style_ac: 0,
      style_options: [
        { url: require('../../../image/pic-wstyle1.png'), className: 'wstyle-line' },
        { url: require('../../../image/pic-wstyle2.png'), className: 'wstyle-line' },
        { url: require('../../../image/pic-wstyle3.png'), className: '' },
        { url: require('../../../image/pic-wstyle4.png'), className: '' },
        { url: require('../../../image/pic-wstyle5.png'), className: 'wstyle-line' },
        { url: require('../../../image/pic-wstyle6.png'), className: '' },
        { url: require('../../../image/pic-wstyle7.png'), className: '' },
        { url: require('../../../image/pic-wstyle8.png'), className: '' },
        { url: require('../../../image/pic-wstyle9.png'), className: 'wstyle-line' },
        { url: require('../../../image/pic-wstyle10.png'), className: '' }
      ],
      searchWhere: {
        title: ''
      },
      tableData: [],
      type_arr: [],
      total: 0,
      current_page: 1,
      per_page: 14
    }
  },
  mounted() {
    this.onSearch()
    this.getStyle()
  },
  methods: {
    // 选择图片样式
    chooseStyle(id) {
      this.is_style_ac = id
      console.log(this.is_style_ac)
    },
    submitStyle () {
       this.get('/admin/Config/setValue', {key:'activity_show_type',value:this.is_style_ac}, 'POST').then(e => {
          this.$message({
            message: '修改成功',
            type: 'success'
          });
          this.getStyle()
      })
    },
    getStyle () {
      this.get('/admin/Config/getValue', {key:'activity_show_type'}, 'POST').then(e => {
          this.is_style_ac = e
      }) 
    },
    changeEdit(id) {
      this.$store.commit('user/SET_EDITID',id)
      this.$store.commit('user/SET_EDIT',12)
    },
    // 查询
    handleSizeChange(val) {
      this.onSearch()
    },
    handleCurrentChange(val) {
      this.current_page = val
      this.onSearch()
    },
    onSearch() {
      const form = {}
      form.page = this.current_page
      form.map = this.searchWhere
      this.get('/admin/Activity/index', form, 'POST').then(e => {
        this.tableData = e.list.data
        this.per_page = e.list.per_page
        this.total = e.list.total
        this.type_arr = e.type_arr
        this.current_page = e.list.current_page
      })
    },
    // 添加
    onAdd() {},
    // 编辑
    onEdit(id) {
      console.log(id)
    },
    // 修改状态
    change_status(id, field, val) {
      this.update(id, val, field, 'Activity').then(e => {
        e ? this.onSearch() : ''

      })
    },
    // 删除
    onDel(id) {
      this.$msg_confirm().then(e => {
        if (e) {
          this.get('/admin/Activity/del?id=' + id, this.form, 'POST').then(e => {
            this.onSearch()

          })
        }
      })
    }
  }
}
</script>

<style scoped>

.layout-all {
  margin-top: 20px;
  margin-left: 10px;
}
.layout-content {
  margin-top: 20px;
}
.activity-style {
  padding-bottom:20px;
}
 ul li {
    float: left;
    height: 50px;
    padding: 0 9px 7px;
    border-bottom: 2px solid transparent;
    cursor: pointer;
}
.style-ac {
    border-bottom-color: #1aa6ff;
}
.activity-style .wstyle-line {
    position: relative;
    margin-right: 18px;
}
.wstyle-line:before {
    content: '';
    position: absolute;
    top: 0;
    right: -10px;
    width: 1px;
    height: 50px;
    border-left: 1px dashed #999;
}
</style>>
